package com.gym.controller.form.admin;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class UpdateTrainerForm  extends ActionForm {
	
	String trainerfirstname;
	String trainerlastname;
	String trainerphone;
	String traineremail;
	String trainerskill;
	String trainernote;
	
	public String getTrainerfirstname() {
		return trainerfirstname;
	}
	public void setTrainerfirstname(String trainerfirstname) {
		this.trainerfirstname = trainerfirstname;
	}
	public String getTrainerlastname() {
		return trainerlastname;
	}
	public void setTrainerlastname(String trainerlastname) {
		this.trainerlastname = trainerlastname;
	}
	public String getTrainerphone() {
		return trainerphone;
	}
	public void setTrainerphone(String trainerphone) {
		this.trainerphone = trainerphone;
	}
	public String getTraineremail() {
		return traineremail;
	}
	public void setTraineremail(String traineremail) {
		this.traineremail = traineremail;
	}
	public String getTrainerskill() {
		return trainerskill;
	}
	public void setTrainerskill(String trainerskill) {
		this.trainerskill = trainerskill;
	}
	public String getTrainernote() {
		return trainernote;
	}
	public void setTrainernote(String trainernote) {
		this.trainernote = trainernote;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,	HttpServletRequest request) {

		ActionErrors errorsAdmin= new ActionErrors();

		if(getTrainerfirstname()==null || getTrainerfirstname().isEmpty()){
			errorsAdmin.add("trainerfirstname", new ActionMessage("it.errore.nome.obbligatorio"));}
		
		if(getTrainerlastname()==null || getTrainerlastname().isEmpty()){
			errorsAdmin.add("trainerlastname", new ActionMessage("it.errore.cognome.obbligatorio"));}
		
		if(getTrainerphone()==null || getTrainerphone().isEmpty()){
			errorsAdmin.add("trainerphone", new ActionMessage("it.errore.telefono.obbligatorio"));}
		
		if(traineremail==null || traineremail.isEmpty())
			errorsAdmin.add("email" , new ActionMessage("it.errore.email.obbligatorio"));
		else if( ! traineremail.matches("[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}"))
			errorsAdmin.add("traineremail", new ActionMessage("it.errore.email.formato"));
		
		if(getTrainerskill()==null || getTrainerskill().isEmpty()){
			errorsAdmin.add("trainerskill", new ActionMessage("it.errore.skill.obbligatorio"));}
		
		return errorsAdmin;
		
	
		
	}
}
